<!DOCTYPE html>
<html>
<meta charset="utf-8">
<head th:include="include :: header"></head>
<body class="gray-bg">
<div class="wrapper wrapper-content ">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-content">
                    <form class="form-horizontal m-t" id="signupForm">
                        <div class="form-group">
                            <label class="col-sm-3 control-label">考试名称：</label>
                            <div class="col-sm-8">
                                <input id="kaoshiname" name="kaoshiname" class="form-control" type="text" required=""
                                       aria-required="true">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">开始时间：</label>
                            <div class="col-sm-8">
                                <input type="text" class="form-control" id="begintime" name="begintime" readonly
                                       placeholder="yyyy-MM-dd HH:mm:ss" required=""
                                       aria-required="true">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">结束时间：</label>
                            <div class="col-sm-8">
                                <input type="text" class="form-control" id="endtime" name="endtime" readonly
                                       placeholder="yyyy-MM-dd HH:mm:ss" required=""
                                       aria-required="true">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">判断题个数：</label>
                            <div class="col-sm-8">
                                <input id="panduannum" name="panduannum" class="form-control" type="text" required=""
                                       aria-required="true" onblur="check()" placeholder="只能填入数字">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">判断题分值：</label>
                            <div class="col-sm-8">
                                <input id="panduanzhi" name="panduanzhi" class="form-control" type="text" required=""
                                       aria-required="true" onblur="check()" placeholder="只能填入数字">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">单选题个数：</label>
                            <div class="col-sm-8">
                                <input id="danxuannum" name="danxuannum" class="form-control" type="text" required=""
                                       aria-required="true" onblur="check()" placeholder="只能填入数字">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">单选题分值：</label>
                            <div class="col-sm-8">
                                <input id="danxuanzhi" name="danxuanzhi" class="form-control" type="text" required=""
                                       aria-required="true" onblur="check()" placeholder="只能填入数字">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">多选题个数：</label>
                            <div class="col-sm-8">
                                <input id="duoxuannum" name="duoxuannum" class="form-control" type="text" required=""
                                       aria-required="true" onblur="check()" placeholder="只能填入数字">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">多选题分值：</label>
                            <div class="col-sm-8">
                                <input id="duoxianzhi" name="duoxianzhi" class="form-control" type="text" required=""
                                       aria-required="true" onblur="check()" placeholder="只能填入数字">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">总分：</label>
                            <div class="col-sm-8">
                                <input id="zongfen" name="zongfen" class="form-control" type="text" required=""
                                       aria-required="true" onblur="check()" readonly>
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="col-sm-8 col-sm-offset-3">
                                <button type="submit" class="btn btn-primary">提交</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
<div th:include="include::footer"></div>
<script>
    $().ready(function () {
        validateRule();
    });

    $.validator.setDefaults({
        submitHandler: function () {
            save();
        }
    });

    function check() {
        debugger
        var panduannum = $('#panduannum').val()
        var panduanzhi = $('#panduanzhi').val()
        var danxuannum = $('#danxuannum').val()
        var danxuanzhi = $('#danxuanzhi').val()
        var duoxuannum = $('#duoxuannum').val()
        var duoxianzhi = $('#duoxianzhi').val()
        var zongfen = $('#zongfen').val()
        var re = new RegExp("^[0-9]*$");
        if (!re.test(panduannum) && panduannum != '') {
            layer.msg("判断题个数只能填入数字");
            var panduannum = $('#panduannum').val("")
            return;
        }
        if (!re.test(panduanzhi) && panduanzhi != '') {
            layer.msg("判断题分值只能填入数字");
            var panduannum = $('#panduanzhi').val("")
            return;
        }
        if (!re.test(danxuannum) && danxuannum != '') {
            layer.msg("单选题个数只能填入数字");
            var panduannum = $('#danxuannum').val("")
            return;
        }
        if (!re.test(danxuanzhi) && danxuanzhi != '') {
            layer.msg("单选题分值只能填入数字");
            var panduannum = $('#danxuanzhi').val("")
            return;
        }
        if (!re.test(duoxuannum) && duoxuannum != '') {
            layer.msg("多选题个数只能填入数字");
            var panduannum = $('#duoxuannum').val("")
            return;
        }
        if (!re.test(duoxianzhi) && duoxianzhi != '') {
            layer.msg("多选题分值只能填入数字");
            var panduannum = $('#duoxianzhi').val("")
            return;
        }
        $('#zongfen').val(panduannum * panduanzhi + danxuannum * danxuanzhi + duoxuannum * duoxianzhi)
    }

    function save() {
        layer.confirm('提交后不可以修改', {
            btn: ['提交', '不提交'] //按钮
        }, function (index) {
            $.ajax({
                cache: true,
                type: "POST",
                url: "/contract/testpaper/save",
                data: $('#signupForm').serialize(),// 你的formid
                async: false,
                error: function (request) {
                    parent.layer.alert("Connection error");
                },
                success: function (data) {
                    if (data.code == 0) {
                        parent.layer.msg("操作成功");
                        parent.reLoad();
                        var index2 = parent.layer.getFrameIndex(window.name); // 获取窗口索引
                        parent.layer.close(index2);

                    } else {
                        parent.layer.alert(data.msg)
                        layer.close(index);
                    }

                }
            });
        }, function () {

        });


    }

    function validateRule() {
        var icon = "<i class='fa fa-times-circle'></i> ";
        $("#signupForm").validate({
            rules: {
                name: {
                    required: true
                }
            },
            messages: {
                name: {
                    required: icon + "请输入姓名"
                }
            }
        })
    }

    layui.use('laydate', function () {
        var laydate = layui.laydate;
        laydate.render({
            elem: '#begintime',
            type: 'datetime'
        });
        laydate.render({
            elem: '#endtime',
            type: 'datetime'
        });
    });
</script>
</body>
</html>
